package com.hk.jmm.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hk.jmm.R;
import com.hk.jmm.model.RegisterModel;
import com.hk.jmm.presenter.RegisterPresenter;
import com.skyz.base.activity.BaseMvpActivity;

import java.util.List;

public class RegisterActivity extends BaseMvpActivity<RegisterModel, RegisterActivity, RegisterPresenter> {
    public static void showActivity(Activity activity) {
        Intent intent = new Intent(activity, RegisterActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onMessageEvent(Object event) {

    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_regster;
    }


    public EditText et_phone,et_code,et_pass,et_pass_again;
    public ImageView sys_btn_show,sys_btn_show_again;

    public TextView click_save,click_send_code;



    @Override
    protected void onLayoutInflated() {
        setLayoutFullScreen(true);
        et_phone =findViewById(R.id.et_phone);
        et_code =findViewById(R.id.et_code);
        et_pass =findViewById(R.id.et_pass);
        et_pass_again =findViewById(R.id.et_pass_again);

        sys_btn_show =findViewById(R.id.sys_btn_show);
        sys_btn_show_again =findViewById(R.id.sys_btn_show_again);

        click_save =findViewById(R.id.click_save);
        click_send_code =findViewById(R.id.click_send_code);


        TextWatcher textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                getMvpPresenter().checkNull();
            }
        };
        et_phone.addTextChangedListener(textWatcher);
        et_code.addTextChangedListener(textWatcher);
        et_pass.addTextChangedListener(textWatcher);
        et_pass_again.addTextChangedListener(textWatcher);

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        findViewById(R.id.click_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        click_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMvpPresenter().register();
            }
        });

        sys_btn_show.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMvpPresenter().sysShow(sys_btn_show,et_pass);

            }
        });

        sys_btn_show_again.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMvpPresenter().sysShow(sys_btn_show_again,et_pass_again);

            }
        });

        click_send_code.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getMvpPresenter().sendCode();

            }
        });
    }

    @Override
    protected RegisterPresenter initMvpPresenter() {
        return new RegisterPresenter(this, getLifecycle());
    }

    @Override
    protected void onDestroy() {
        getMvpPresenter().onDestroy();
        super.onDestroy();
    }
}
